-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(server): full vehicle persistence #621
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidentally approved. Ignore this comment.
server/vehicle-persistence.lua
Outdated
@@ -1,3 +1,6 @@ | |||
local persistence = GetConvarInt('qbx:enableVehiclePersistence', 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change. Either keep the convar as a string an overload the meaning (right now values are 'true' or 'false. We could add 'full' as well. OR add a new true/false convar which controls whether vehicles are persisted between restarts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, values "true"
and "false"
are interpreted as 1
and 0
respectively by GetConvarInt
. But at this point this can actually be replaced by the new GetConvarBool
I believe, which is available since artifact 10543 — we require 10731.
server/vehicle-persistence.lua
Outdated
print('Vehicle persistence mode ' .. persistence) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
server/vehicle-persistence.lua
Outdated
}) | ||
exports.qbx_core:EnablePersistence(veh) | ||
Entity(veh).state:set('vehicleid', id, false) | ||
SetVehicleDoorsLocked(veh, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use qbx_vehiclekeys for this, as setting it directly bypasses checks and such that qbx_vehiclekeys does. Best to make it a config function of core so that people can input other key systems they might be running
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I see, but there's no export in qbx_vehiclekeys to lock a car ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll have to create one. Just extract the implementation of qb-vehiclekeys:server:setVehLockState into an export.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okey I see, I'll create a pr in qbx_vehiclekeys then.
server/vehicle-persistence.lua
Outdated
model = model, | ||
props = props | ||
}) | ||
exports.qbx_core:EnablePersistence(veh) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qbx.spawnVehicle already sets this.
server/vehicle-persistence.lua
Outdated
|
||
lib.callback.register('qbx_core:server:getVehiclesToSpawn', function() | ||
local vehicles = {} | ||
local query = 'SELECT id, plate, coords FROM player_vehicles WHERE state = 0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use https://docs.qbox.re/resources/qbx_vehicles/exports/server#getplayervehicles rather than directly querying the sql table
server/vehicle-persistence.lua
Outdated
lib.callback.register('qbx_core:server:getVehiclesToSpawn', function() | ||
local vehicles = {} | ||
local query = 'SELECT id, plate, coords FROM player_vehicles WHERE state = 0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than being queried by every player. This data should be queried on server startup and cached. Then, as vehicles get spawned, the cache gets smaller and smaller.
server/vehicle-persistence.lua
Outdated
RegisterNetEvent('qbx_core:server:spawnVehicle', function(id, coords) | ||
local vehicle = exports.qbx_vehicles:GetPlayerVehicle(id) | ||
if not vehicle then return end | ||
spawnVehicle(coords, id, vehicle.modelName, vehicle.props) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an exploitable event. Needs a server side check. Once a cache exists, you can use it to verify that the id vehicle exists in cache near the specified coords
Description
This pull request will add the possibility to qbox users to enable a full vehicle persistence so that cars never despawn even after server restart. I tested this code with 10 people on a clean qbox server.
The convar
qbx:enableVehiclePersistence
has been modified :Checklist